#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int thirdMax(vector<int>& nums) {
        int max1, max2, max3;
        max1 = max2 = max3 = -1;
        for(int i = 0; i < nums.size(); ++i){
            int* minNum = min(&max1, &max2, &max3);
            if(*minNum < nums[i])
                *minNum = nums[i];
            cout << max1 << " " << max2 << " " << max3 << endl;
        }
        if(nums.size() >= 3)
            return *min(&max1, &max2, &max3);
        else{
            return max1 > max2 ? (max1 > max3 ? max1 : max3) : (max2 > max3 ? max2 : max3);
        }
    }
    int* min(int* max1, int* max2, int* max3){
        int* min = max1;
        if(*min > *max2)
            min = max2;
        if(*min > *max3)
            min = max3;
        return min;
    }
};

int main(){
    int arr[] = {2, 2, 3, 1};
    int len = sizeof(arr)/sizeof(int);
    vector<int> vec;
    for(int i = 0; i < len; ++i){
        vec.push_back(arr[i]);
    }
    Solution* s = new Solution();
    cout << s->thirdMax(vec) << endl;
    delete s;
    return 0;
}